package com.pet.server.ext.action.article;


import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.Config;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.Article;
import com.pet.server.ext.service.ArticleService;
import com.pet.server.ext.util.JsonUtil;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;

import net.sf.json.JSONObject;

public class Info extends ActionBase{
	public Integer article_id;
	public String wechat="0";
	public Info(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		article_id = NumberUtil.getInteger(params.getFieldValue("article_id"), 0);
	}
	
	@Override
	public Result invokeService() throws ApiError {
		ArticleService articleService = new ArticleService();
		Article article = articleService.findArticle(article_id);
		if(null==article){
			throw ApiError.Type.LOGIC_ERROR.toException();
		}
		Result result = new Result();
        JSONObject data = new JSONObject();
        data.put("title", article.getTitle());
        data.put("create_time", JsonUtil.getTime(article.getCreate_time()));
        //data.put("description", article.getDescription());
        data.put("context", StringUtil.appendCss(Config.getValue("server.name"),article.getText()));
        data.put("share_url", Config.getValue("server.name")+"/article/detail.do?article_id="+article.article_id);

        result.put("data", data);
        
        
        
        
        
	    return result;
	}
	
	


}
